<template>
  <div
    class="TextView">
    <!--    头部标题-->
    <div
      class="showText">
      让鱼子日丰富你的文本吧
    </div>
    <!--文本输入框-->
    <div
      class="text">
      <textarea
        v-model="textarea"
        placeholder="大家好，今天给大家讲一讲人工智能，人工智能真的很好，可以实现很多功能，提高我们的工作效率。">
      </textarea>
      <span>
        {{
          textarea.length
        }}/1000
      </span>
    </div>
    <!--    文本格式-->
    <div
      class="format">
      <choose
        :info="format"></choose>
    </div>
    <!--    文笔风格-->
    <div
      class="format">
      <choose
        :info="styles"></choose>
    </div>
    <!--    字数范围-->
    <div
      class="Radius">
      <div
        class="header">
        字数范围
      </div>
      <div
        class="change">
        <input
          type="number"
          v-model="minText"
          name=""
          id="">
        <span>
          ——
      </span>
        <input
          v-model="maxText"
          type="number"
          name=""
          id="">
      </div>
    </div>
    <!--    剩余次数-->
    <div
      class="last">
      <span>————————</span>
      <p>
        今日剩余次数：{{
          lastNum
        }}次</p>
      <span>————————</span>
    </div>
    <!--    底部点击按钮-->
    <div
      class="footer"
      @click="gerenate">
      AI生成
    </div>
  </div>
</template>

<script>
import Choose
  from "../components/choose.vue";

export default {
  name: "textView",
  components: {Choose},
  data() {
    return {
      textarea: "",
      format: {
        type: "文本格式",
        children: ["智能", "演讲稿", "记述文", "新闻稿", "说明文", "书评"]
      },
      styles: {
        type: "文笔风格",
        children: ["智能", "鲁迅", "王小波", "余华", "乌拉尼亚", "村上春树", "时间段"]
      },
      minText: 0,
      maxText: 200,
      lastNum: 10
    }
  },
  watch: {
    minText(newvalue, oldvalue) {
      if (this.minText > this.maxText) {
        alert('输入有误')
        this.minText = oldvalue
      }
    },
    maxText(newvalue, oldvalue) {
      if (this.maxText < this.minText) {
        alert('输入有误')
        this.maxText = oldvalue
      }
    },
    textarea(newvalue, oldvalue) {
      if (this.textarea.length > 1000) {
        alert('字数超出最大显示')
        this.textarea = oldvalue
      }
    }
  },
  methods: {
    gerenate() {
      if (this.textarea) {
        this.lastNum--
        if (this.lastNum < 0) {
          this.lastNum = 0
          alert('已无生成次数')
        }else{
          alert('生成成功')
        }
      } else {
        alert('请先输入内容')
      }
    }
  }
}
</script>

<style
  scoped
  lang="less">
.TextView {
  width: 100%;
  height: 100%;

  .showText {
    width: 100%;
    height: 40px;
    font-size: 16px;
    color: #ced0d5;
    line-height: 40px;
    padding-left: 20px;
  }

  .text {
    width: 100%;
    height: 320px;
    padding: 5px 15px;
    position: relative;

    textarea {
      width: 100%;
      height: 310px;
      border: none;
      outline: none; /*边线不显示*/
      resize: none; /*禁止拉伸*/
      appearance: none;
      background-color: rgba(255, 255, 255, .5);
      border-radius: 10px;
      padding: 10px;
      font-size: 13px;
      color: #d7d9dc;
    }

    ::-webkit-input-placeholder {
      color: #d7d9dc;
    }

    span {
      position: absolute;
      bottom: 15px;
      right: 25px;
      color: #ada9ad;
    }
  }

  .Radius {
    width: 100%;
    height: 55px;
    margin-top: 25px;
    padding-left: 15px;

    .header {
      font-size: 14px;
      color: #d2d0d3;
    }

    .change {
      margin-top: 10px;
      display: flex;
      align-items: center;

      input {
        height: 18px;
        border: 2px solid #a29da3;
        border-radius: 9px;
        color: #fff;
        width: 80px;
        background-color: rgba(255, 255, 255, .5);
        text-align: center;
      }
      //谷歌
      input::-webkit-outer-spin-button,
      input::-webkit-inner-spin-button {
        -webkit-appearance: none;
      }

      //火狐
      input[type="number"]{
        -moz-appearance: textfield;
      }

      span {
        margin: 0 10px;
      }
    }
  }

  .last {
    width: 100%;
    height: 40px;
    position: fixed;
    bottom: 60px;
    left: 0;
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 0 20px;
  }

  .footer {
    position: fixed;
    bottom: 0;
    left: 0;
    font-size: 24px;
    color: #fff;
    text-align: center;
    line-height: 60px;
    height: 60px;
    width: 100%;
    background: linear-gradient(-45deg, #005cff, #ff0019);
  }
}
</style>
